package com.sbcb.http;

import com.sbcb.http.filter.AddResponseHeaderFilter;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.annotation.Bean;

@ServletComponentScan //会扫描Filter
@SpringBootApplication
public class HttpApplication {
    //入口类注册Filter
    @Bean //将方法中返回的对象注入到IOC容器中
    public FilterRegistrationBean filterRegister(){
        FilterRegistrationBean reFilter = new FilterRegistrationBean();
        reFilter.setFilter(new AddResponseHeaderFilter()); //创建并注册TestFilter
        reFilter.addUrlPatterns("/*"); //拦截的路径（对所有请求拦截）
        reFilter.setName("addResponseHeaderFilter"); //拦截器的名称
        reFilter.setOrder(1); //拦截器的执行顺序。数字越小越先执行
        return  reFilter;

    }

    public static void main(String[] args) {
        SpringApplication.run(HttpApplication.class, args);
    }

}
